#include "TextEncoding.h"

#if defined(Q_OS_WIN)
#include "windows.h"

#else

#include <QString>

#endif

#if defined(Q_OS_WIN)
std::wstring utf82ws(std::string utf8) {
	std::wstring ret;
	ret.resize(::MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), (int)utf8.size(), 0, 0));
	::MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(), (int)utf8.size(), &ret[0], (int)ret.size());
	return ret;
}

std::string ws2utf8(std::wstring ws) {
	std::string ret;
	ret.resize(::WideCharToMultiByte(CP_UTF8, 0, ws.c_str(), (int)ws.size(), 0, 0,0,0));
	::WideCharToMultiByte(CP_UTF8, 0, ws.c_str(), (int)ws.size(), &ret[0], (int)ret.size(),0,0);
	return ret;
}
#elif defined (Q_OS_MAC)

std::wstring utf82ws(std::string utf8) {
    QString v = QString::fromStdString(utf8);
    return v.toStdWString();
}

std::string ws2utf8(std::wstring ws) {
    QString v = QString::fromStdWString(ws);
    return v.toStdString();
}
#endif
